package com.example.test.service.factory;

import com.example.test.service.impl.loginImpl1;
import com.example.test.service.impl.loginImpl2;
import com.example.test.service.login;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class LoginFactory implements ApplicationContextAware {

    private Map<String, login> LOGIN_MAP = new HashMap<>();

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        LOGIN_MAP.put("1",applicationContext.getBean(loginImpl1.class));
        LOGIN_MAP.put("2",applicationContext.getBean(loginImpl2.class));
    }

    public login getLogin(String code){
        return LOGIN_MAP.get(code);
    }
}
